package com.shiwaixiangcun.monitor.repository;

import com.rabbit.spring.data.repository.GenericJpaRepository;
import com.shiwaixiangcun.monitor.domain.EarlyWarning;
import com.shiwaixiangcun.monitor.domain.WorkOrder;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by Administrator on 2017-11-22.
 */
public interface EarlyWarningRepository extends GenericJpaRepository<EarlyWarning, Long> {

    @Query("select max(number) from EarlyWarning where companyId =:organizationId")
    String findNumberByCompanyId(@Param("organizationId") Long organizationId);

    EarlyWarning findByWorkOrder(WorkOrder workOrder);

    @Query("select e from EarlyWarning e where e.id in(select max(ew.id) from EarlyWarning ew group by ew.identifier)")
    List<EarlyWarning> getWarningAllList();

}
